package com.hengda.museumonline.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hengda.museumonline.R;
import com.hengda.museumonline.entity.DomesticBean;
import com.hengda.museumonline.utils.GlideCircleTransform;

import java.util.List;

import static com.yolanda.nohttp.NoHttp.getContext;

/**
 * @author：JFWU on 2016/9/26 18:36
 * @E-mail：jeffy12138@126.com
 */
public class DomesticAdapter extends RecyclerView.Adapter<DomesticAdapter.ListHolder> {
    private Context context;
    private DomesticBean domesticBean;


    public DomesticAdapter(Context context, DomesticBean domesticBean) {
        this.context = context;
        this.domesticBean = domesticBean;
    }

    @Override
    public DomesticAdapter.ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.domestic_item, parent, false);

        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(DomesticAdapter.ListHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return domesticBean.getData().size();
    }

    class ListHolder extends RecyclerView.ViewHolder {
        private TextView postTitle;
        private TextView postModified;
        private TextView postSource;
        private ImageView img;


        public ListHolder(View itemView) {
            super(itemView);
            postTitle = (TextView) itemView.findViewById(R.id.post_title);
            postModified = (TextView) itemView.findViewById(R.id.post_modified);
            postSource = (TextView) itemView.findViewById(R.id.post_source);
            img = (ImageView) itemView.findViewById(R.id.img);

        }

        public void setData(int position) {
            postTitle.setText(domesticBean.getData().get(position).getPost_title());
            postModified.setText(domesticBean.getData().get(position).getPost_modified().substring(0,10));
            postSource.setText(domesticBean.getData().get(position).getPost_source());
            Glide.with(getContext()).load(domesticBean.getData().get(position).getImg()).placeholder(R.mipmap.cheese_1).into(img);

        }


    }
}
